home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15246 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: newsxfer2.itd.umich.edu!caen!hasdi
  2. From: hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM)
  3. Newsgroups: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
  4. Subject: Re: typecasting preferences
  5. Followup-To: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
  6. Date: 18 Apr 1996 05:53:47 GMT
  7. Organization: University of Michigan Engineering, Ann Arbor
  8. Distribution: world
  9. Message-ID: <4l4ldb$nkl@srvr1.engin.umich.edu>
  10. References: <4l020g$i9j@srvr1.engin.umich.edu> <Pine.A32.3.91.960416145209.106109C-100000@black.weeg.uiowa.edu>
  11. NNTP-Posting-Host: neon.engin.umich.edu
  12. X-Newsreader: TIN [version 1.2 PL2]
  13.  
  14. The Amorphous Mass (robinson@blue.weeg.uiowa.edu) wrote:
  15. : On 16 Apr 1996, HASDI RODZMANN HASHIM wrote:
  16.  
  17. :   C-style.  Especially since C types can contain multiple tokens;
  18.  
  19. :   const char *(p) is less clear IMO than (const char *)p.
  20.  
  21. Hmm.... another thing about pascal is that dereferencer is postfix 
  22. instead of prefix. That way, I can cast a void * (Pascal - pointer) into 
  23. something else...
  24.  
  25. C-style:
  26.     typedef myrecord_s {...} myrecord,*myrec;
  27.  
  28.     my_int = ((myrecord*)myvar)->intA; /* yeach! */
  29. or...
  30.     my_int = (*(myrecord*)myvar).intA; /* see above */    
  31.  
  32. Pascal-syle:
  33.     myrecp : ^myrecord;
  34.     myrecord : record ... end;
  35.  
  36.     myInt := myrecp(myvar)^.intA; { looks clean }
  37.     myInt := ^myrecord(myvar)^.intA; { compile error? }
  38.  
  39. Remix:
  40.     my_int = myrecp(myvar)*.intA;
  41. or...
  42.     my_int = myrecord*(myvar)*.intA; /* ouch! */
  43.  
  44. Some people mentioned about type-casting != type-conversion and C++ use
  45. makes distinction between them using cast-notation (c-style) and
  46. function-notation (pascal-style). I think I am getting the hang of the
  47. differences; I had to talk to my professor and read C++ draft to figure
  48. out what it going on. 
  49.  
  50. The way I understand it, type-conversion is to transform the bits of one
  51. variable so that it is representable as the type to be converted into. eg. 
  52. (int)my_float. type-casting doesn't transform the bits at all, but force
  53. the compiler to treat that variable as the specified type... which is
  54. highly unportable. Why would anyone want to typecast then? Can somebody
  55. clarify this for me? 
  56.  
  57. As a side note, using typedef so that you can use "myrecord" instead of
  58. "struct myrecord_s" has been a real major bug to me. Unfortunately, this
  59. is necessary to avoid shift/reduce conflicts. Makes me wonder how C++
  60. parser works. (If I stick to Pascal-style, this would also mean I have to
  61. redesign the declaration section, C-style or Pascal? But that's another
  62. story.)
  63.  
  64. Thanks guys!
  65.  
  66. Hasdi
  67.  
  68.